function gewMeshNode(name)
{ 
  gewNode.call(this,name);
  this.currentLOD = 0;
  this.mesh = null;  
  this.shouldCreatePhysicsBody = false;
}
//gewMeshNode.prototype = new gewNode();
extend2(gewMeshNode, gewNode);

gewMeshNode.prototype.setMesh = function(mesh)
{
  this.mesh = mesh;
  this.localAabb = mesh.aabb;
  this.localSphere = mesh.boundingSphere;
  this.setFlag(NODE_UPDATE_TRANSLATE_MAT,true);// to force this node update world bounding volume; 
}
gewMeshNode.prototype.dup = function()
{
  var copy = new gewMeshNode(this.name+"_"+getUniqueNumber());
  copy.copyFrom(this);
  copy.setMesh(this.mesh);
  copy.shouldCreatePhysicsBody = this.shouldCreatePhysicsBody;
  return copy;
}
gewMeshNode.prototype.getMesh = function()
{
  return this.mesh;
}

gewMeshNode.prototype.setAttributePointers = function(material)
{
  var m = this.mesh; 
  var effect = material.effect;
  var gl = this.gl;
  ///////////////////////////////////////////////////////////////////////////////
  //Set up vertex attribute pointers
  switch (effect.name) {
    case "PhongEffect":
    case "PhongNoShadowEffect":
      var shader = effect.shader;
      gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.positions);
      gl.vertexAttribPointer(shader.inPosition, 3, gl.FLOAT, false, 0, 0);
      gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.texcoords);
      gl.vertexAttribPointer(shader.inTexCoord0, 2, gl.FLOAT, false, 0, 0);
      gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.normals);
      gl.vertexAttribPointer(shader.inNormal, 3, gl.FLOAT, false, 0, 0);
      break;
    case "CSMEffect":
      if (material.type == GEW_SHADOW_MESH) {
        gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.positions);
        gl.vertexAttribPointer(effect.shaders.mesh.inPosition, 3, gl.FLOAT, false, 0, 0);
      }
      else 
        if (material.type == GEW_SHADOW_ALPHA_REF) {
          gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.positions);
          gl.vertexAttribPointer(effect.shaders.alphaRef.inPosition, 3, gl.FLOAT, false, 0, 0);
          gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.texcoords);
          gl.vertexAttribPointer(effect.shaders.alphaRef.inTexCoord0, 2, gl.FLOAT, false, 0, 0);
        }
      break;
    case "DepthMaskEffect":
      var shader = effect.shaders.mesh;
      gl.bindBuffer(gl.ARRAY_BUFFER, m.glBuffers.positions);
      gl.vertexAttribPointer(shader.inPosition, 3, gl.FLOAT, false, 0, 0);
      break;
  }
}
gewMeshNode.prototype.render = function(material)
{
  var m = this.mesh; 
  var effect = material.effect;
  var gl = this.gl;  
  /////////////////////////////////////////////////////////////////////////////////////
  // Draw mesh
  if (m.renderType == GEW_TRIANGLES_NON_INDICES) 
  {
    var ver_num = m.vertices.length / 3;
    gl.drawArrays(gl.TRIANGLES, 0, ver_num);
  }
  else if(m.renderType== GEW_TRIANGLES_INDICES)
  {
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, m.glBuffers.indices[this.currentLOD]);
    gl.drawElements(gl.TRIANGLES,m.indices[this.currentLOD].length,gl.UNSIGNED_SHORT,0);
  }            
}

